package com.neborosoft.FlyingDog.android.gui.adapters.ViewPagerAdapters;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import com.neborosoft.FlyingDog.R;
import com.neborosoft.FlyingDog.android.gui.adapters.listview.SongsPlayListAdapter;
import com.neborosoft.FlyingDog.logic.database.content.identified.ArtSize;
import com.neborosoft.FlyingDog.logic.database.content.identified.Audio;
import com.neborosoft.android.gui.adapters.viewpager.ElementsProvidingPagerAdapter;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created with IntelliJ IDEA.
 * User: CM
 * Date: 11.11.12
 * Time: 17:19
 * To change this template use File | Settings | File Templates.
 */
public abstract class SongsPagerAdapter extends ElementsProvidingPagerAdapter<Audio> {
    private static final ArtSize ART_SIZE = ArtSize.LARGE;
    private static final ImageLoader IMAGE_LOADER = ImageLoader.getInstance();

    protected SongsPagerAdapter(Context context) {
        super(context);
    }

    private static SongsPlayListAdapter getSongsAdapter(){
        SongsPlayListAdapter songsPlayListAdapter = SongsPlayListAdapter.getSelectedSongsAdapter();
        if(songsPlayListAdapter == null){
            throw new IllegalStateException("cannot access to SongsPagerAdapter," +
                    " when song is not selected");
        }

        return songsPlayListAdapter;
    }

    @Override
    protected Audio getElement(int position) {
        SongsPlayListAdapter songsPlayListAdapter = getSongsAdapter();
        return songsPlayListAdapter.getElement(position);
    }

    @Override
    protected int getRootLayoutId() {
        return R.id.mainWindowAlbumArt;
    }

    @Override
    protected void fillAudio(View view, Audio audio) {
        IMAGE_LOADER.displayImage(audio.getArtUrl(ART_SIZE),(ImageView)view);
    }

    @Override
    public int getCount() {
        SongsPlayListAdapter songsPlayListAdapter = getSongsAdapter();
        return songsPlayListAdapter.getCount();
    }
}
